home *** CD-ROM | disk | FTP | other *** search
- <![CDATA[
-
- // BUGBUG: Need to create CPVResults/CCVResults to store lookup data and CPV/CCV to encapsulate Lookup
- // BUGBUG: Rather than accessing global goLookup, pass this into the CPV and CCV constructor
-
- // Encapsulation of possible value results data
- function CPVData()
- {
- // this.Init();
- }
-
- CPVData.prototype.Init = function()
- {
- this.caption = "";
- this.devlang = "";
- this.error = "";
- this.className = "";
- this.pid = "";
- this.rid = "";
- }
-
- function CCVData()
- {
- // this.Init();
- }
-
- CCVData.prototype.Init = function()
- {
- this.caption = "";
- this.devlang = "";
- this.error = "";
- this.cvid = "";
- this.rid = "";
- }
-
- // Lookup the composite value associated with the xref
- function LookupCV(oSrc, oData, sCurLang)
- {
- oData.Init();
-
- var sCVID = oData.caption = oSrc.getAttribute("cvid");
- if (!sCVID)
- {
- oData.error = "expected cvid was not specified.";
- return false;
- }
-
- var sRID = oData.rid = oSrc.getAttribute("rid");
- if (!IsSelfReference(sRID))
- {
- if (!goLookup.RetrieveTarget(sRID))
- {
- oData.error = "unable to find rid '" + sRID + "' among targets.";
- return false;
- }
- }
- else
- {
- var oNode = ownerDocument.selectSingleNode("/inetsdk:topic/content/params/param[@get]/pv[@type='composite']/cv[@name='" + sCVID + "']");
- if (!oNode)
- {
- oData.error = "cvid '" + sCVID + "' not found.";
- return false;
- }
- }
-
- return true;
- }
-
- function GetCVCaption(oSrc, oData)
- {
- return oData.caption;
- }
-
- // Lookup the possible value associated with the specified xref
- function LookupPV(oSrc, oData, sCurLang)
- {
- oData.Init();
-
- var sDevLang = oSrc.getAttribute("devlang"); // author can override the devlang (or specify it in a lang-neutral topic)
- if (!sDevLang)
- {
- sDevLang = sCurLang;
- }
- oData.devlang = sDevLang; // the devlang as defined by the current template
-
- var sPV = oData.caption = oSrc.getAttribute("pvid");
- // the following should never happen
- if (!sPV)
- {
- oData.error = "expected pvid was not specified.";
- return false;
- }
-
- // BUGBUG: Should first determine if the xref is to a doc of type method, function, struct, or enum
- // BUGBUG: Use that info to get the appropriate attribute (@pid, @mid, @cid)
- var sRID = oData.rid = oSrc.getAttribute("rid");
- var bSelfRef = IsSelfReference(sRID);
- var sType;
-
- var sPVType = oSrc.getAttribute("pvtype");
-
- if (bSelfRef)
- {
- sType = ownerDocument.selectSingleNode("/inetsdk:topic/metadata/@type").value;
- }
- else
- {
- if (!sPVType)
- {
- oData.error = "specify pvtype=(range|literal|flag) when pv reference points to remote topic";
- return false;
- }
-
- var oTarget;
- if (!(oTarget = goLookup.RetrieveTarget(sRID)))
- {
- oData.error = "unable to find rid '" + sRID + "' among targets.";
- return false;
- }
- else
- {
- sType = oTarget.getAttribute("type");
- }
- }
-
- var sQuery = "/inetsdk:topic/content/";
- var sMID;
- switch(sType)
- {
- case 'struct':
- sMID = oData.mid = oSrc.getAttribute("mid");
- if (!sMID)
- {
- oData.error = "expected @mid not found.";
- return false;
- }
- sQuery += "members/member[@name='" + sMID + "'][pv]";
- break;
- case 'property':
- case 'method':
- case 'function':
- sMID = oData.pid = oSrc.getAttribute("pid");
- if (!sMID)
- {
- oData.error = "expected @pid not found.";
- return false;
- }
- sQuery += "params/param[@name='" + sMID + "'][pv]";
- break;
- case 'isv_element':
- sMID = oData.aid = oSrc.getAttribute("aid");
- if( !sMID )
- {
- oData.error = "expected @aid not found.";
- return false;
- }
- sQuery += "attribs/attrib[@name='" + sMID + "'][pv]";
- break;
- case 'htmldeclaration':
- sMID = oData.aid = oSrc.getAttribute("aid");
- if( !sMID )
- {
- oData.error = "expected @aid not found.";
- return false;
- }
- sQuery += "attribs/attrib[@name='" + sMID + "'][pv]";
- break;
- default:
- oData.error = "type '" + sType + "' not supported.";
- return false;
- }
-
-
- if (bSelfRef)
- {
- // find the pv among the params/members in the current topic
- var oMember = ownerDocument.selectSingleNode(sQuery);
- if (!oMember)
- {
- oData.error = "param/member '" + sMID + "' not found in current topic.";
- return false;
- }
-
- // lookup name preferentially
- var oPV;
- if (oPV = oMember.selectSingleNode("pv[@name='" + sPV + "']"))
- {
- if (sDevLang == 'scr')
- {
- var sValue = oPV.getAttribute('value');
- if (!sValue)
- {
- oDest.error = "unable to retrieve value from name '" + sPV + "'.";
- return false;
- }
-
- sPV = oData.caption = sValue;
- }
- }
- else if (oPV = oMember.selectSingleNode("pv[@value='" + sPV + "']"))
- {
- // BUGBUG: Disallow this in the C++ case? It's what scripters want but probably not what C++ programmers want.
- }
- else if (oPV = oMember.selectSingleNode("pv[@rid='" + sPV + "']"))
- {
- var oFlag = ownerDocument.selectSingleNode("/inetsdk:topic/flags/flag[@id='" + sPV + "']");
- if (!oFlag)
- {
- oData.error = "flag with id '" + sPV + "' not found.";
- return false;
- }
-
- var sAttr = aFlagAttrMap[sDevLang];
- if (!sAttr)
- {
- oDest.error = "devlang '" + sDevLang + "' not found in flag map.";
- return false;
- }
-
- var sCaption = oFlag.getAttribute(sAttr);
- if (!sCaption)
- {
- oData.error = "flag with id '" + sPV + "' missing '" + sAttr + "' attribute.";
- return false;
- }
- else
- {
- sPV = oData.caption = sCaption;
- }
- }
- else
- {
- oData.error = "pv '" + sPV + "' not found.";
- return false;
- }
- }
-
- if (!sPVType && oPV)
- {
- sPVType = oPV.getAttribute("type");
- }
-
- if (!MapPVTypeToCSSClass(sPVType, oData, sDevLang))
- {
- return false;
- }
-
- return true;
- }
-
- // given a pv/@type of an xref/@pvtype, map to a CSS class for presentation
- function MapPVTypeToCSSClass(sPVType, oData, sDevLang)
- {
- if (!sPVType)
- {
- return false;
- }
-
- switch(sPVType)
- {
- case 'range':
- oData.className = 'clsRange';
- break;
- case 'literal':
- oData.className = 'clsLiteral';
- break;
- case 'flag':
- if (sDevLang == 'scr')
- {
- oData.className = 'clsLiteral';
- }
- else
- {
- oData.className = 'clsFlag';
- }
-
- break;
- otherwise:
- oData.error = "unsupported pvtype '" + sType + "'. Use (range|literal|flag)."
- return false;
- }
-
- return true;
- }
-
- function GetPVCaption(oSrc, oData)
- {
- return oData.caption;
- }
-
- function GetPVClass(oSrc, oData)
- {
- return oData.className;
- }
-
- function GetLastError(o)
- {
- return (o && o.error ? o.error : "unexpected error");
- }
-
- ]]>
-